﻿using SXT.Party.Utility;
using SXT.Party.WomenAndChildrens.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZHDJ.MobileInterface
{
    public partial class GetPartyWCFamilyList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            WCFamilyOutParam result = new WCFamilyOutParam();
            WCFamilyInParam param = new WCFamilyInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as WCFamilyInParam;

                if (isFlag)
                {
                    if (param.page_no * param.page_count <= 0)
                    {
                        result.code = "0";
                        result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    DataSet ds = PartyWCFamily.GetGridData("", param.page_no, param.page_count, "true");

                    if (ds != null && ds.Tables.Count == 2)
                    {
                        PartyFamily itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new PartyFamily();

                            itemTemp.FamilyID = dr["FamilyID"].ToString();
                            itemTemp.Address = dr["Address"].ToString();
                            itemTemp.BusPoint = dr["BusPoint"].ToString();
                            itemTemp.Geographic = dr["Geographic"].ToString();
                            itemTemp.LinkMan = dr["LinkMan"].ToString();
                            itemTemp.LinkPhone = dr["LinkPhone"].ToString();
                            itemTemp.Name = dr["Name"].ToString();
                            itemTemp.Remark = dr["Remark"].ToString();
                            //itemTemp.ImgUrl = dr["ImgID"].ToString();
                            if (!string.IsNullOrEmpty(dr["ImgID"].ToString()))
                            {
                                itemTemp.ImgUrlFirst = CommonUtils.AppAddress + PageUtility.GetImageUrl(dr["ImgID"].ToString());
                                itemTemp.ImgUrlMiddle = CommonUtils.AppAddress + PageUtility.GetImageUrl(dr["ImgID"].ToString(), "_middle");
                                itemTemp.ImgUrlSmall = CommonUtils.AppAddress + PageUtility.GetImageUrl(dr["ImgID"].ToString(), "_small");
                            }
                            else
                            {
                                itemTemp.ImgUrlFirst = itemTemp.ImgUrlMiddle = itemTemp.ImgUrlSmall = CommonUtils.AppAddress + "Resource/themes/default/images/Party/Party-Emblem.jpg";
                            }
                            result.data.list.Add(itemTemp);
                        }
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetPartyWCFamily", SerializeHelper.JsonSerializer<WCFamilyInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<WCFamilyInParam, WCFamilyOutParam>();
            else
                SafeProcessRequest<WCFamilyInParam, WCFamilyOutParam>();
        }
    }

    #region 请求参数
    public class WCFamilyInParam
    {

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class WCFamilyOutParam
    {
        public WCFamilyOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new WCFamily();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 专家来支招
        /// </summary>
        public WCFamily data
        { get; set; }
    }

    public class WCFamily
    {
        public WCFamily()
        {
            total_pages = 0;
            list = new List<PartyFamily>();
        }

        public List<PartyFamily> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    /// <summary>
    /// 专家来支招
    /// </summary>
    public class PartyFamily
    {
        /// <summary>
        ///	ID		
        /// </summary>
        public string FamilyID
        { get; set; }

        /// <summary>
        ///	名称			
        /// </summary>
        public string Name
        { get; set; }

        /// <summary>
        ///	地址		
        /// </summary>
        public string Address
        { get; set; }

        /// <summary>
        ///	联系人			
        /// </summary>
        public string LinkMan
        { get; set; }

        /// <summary>
        ///	联系电话			
        /// </summary>
        public string LinkPhone
        { get; set; }

        /// <summary>
        ///	公交指引			
        /// </summary>
        public string BusPoint
        { get; set; }

        /// <summary>
        ///	地理坐标			
        /// </summary>
        public string Geographic
        { get; set; }

        /// <summary>
        ///	特色			
        /// </summary>
        public string Remark
        { get; set; }

        /// <summary>
        ///	图片			
        /// </summary>
        public string ImgUrlFirst
        { get; set; }

        /// <summary>
        ///	图片			
        /// </summary>
        public string ImgUrlMiddle
        { get; set; }

        /// <summary>
        ///	图片			
        /// </summary>
        public string ImgUrlSmall
        { get; set; }
    }
    #endregion
}